/**
*	Group: Y1
*	The SoundPlayer class takes care of creating objects that handle the audio for the gamming. Each SoundPlayer object reprents a filename
*	which it plays. The class is degined for invoking and stopping audio sounds when game is in play.
*	@author Rahul Kapadia
*/
package lightspeed.Media.Audio;
import sun.audio.*;
import java.io.*;

public class SoundPlayer {

	/**
	*	String which represents the audio WAV file which is being inputed/played.
	*/
	String filename;
	/**
	*	InputStream in order to read in the WAV file
	*/
	InputStream in;
	/**
	*	AudioStream which allow for playing and stopping the read-in WAV file.
	*/
	AudioStream  as;
	/**
	*	Constructor: created an instance of a SoundPlayer object
	*	The Soundplayer object will represent a Audio WAV file which can be manipulated to match the game environment. 
	*	@param filename Strign that holds the name of the WAV audio file
	*/
		public SoundPlayer(String filename)
		{
			try
			{
				this.filename = filename;
				in = new FileInputStream(filename);
				as = new AudioStream(in);
			}
			
			catch (IOException e) 
			{
				e.printStackTrace();
			}          
		}
		/**
		Starts playing the music file that the object holds. The object needs to hold a legitamte and valid filename in order for the music to start playing. 
		*/
	    public void play() 
		{
		
       
			AudioPlayer.player.start(as); 

		}
		/**
		Starts playing the music file that the object holds in loop by creating an instant of ContinousAudioDataStream. The object needs to hold a legitamte and valid filename in order for the music to start playing. 
		*/
		public void playloop()
		{
			AudioData data = null;
			try
			{
				data = as.getData();
				ContinuousAudioDataStream cas = new ContinuousAudioDataStream(data);
				AudioPlayer.player.start(cas);
			}
			catch (IOException e) 
			{
				e.printStackTrace();
			}
		}


		/**
		Stops playing the music file that the object holds. 
		*/
		public void stop() 
		{
		AudioPlayer.player.stop(as); 

		}
		

}
